home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / m4-1_0_3.lha / m4-1.0.3 / m4.h < prev    next >
C/C++ Source or Header  |  1992-12-19  |  9KB  |  357 lines

  1. /* -*- c -*-
  2.  * GNU m4 -- A simple macro processor
  3.  * Copyright (C) 1989-1992 Free Software Foundation, Inc.
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #ifndef __STDC__
  21. #define const
  22. #define Args(x) ()
  23. #else
  24. #define Args(x) x
  25. #endif
  26.  
  27. #ifndef __GNUC__
  28. #define volatile
  29. #else
  30. #define volatile __volatile__
  31. #endif
  32.  
  33. #include <stdio.h>
  34. #include <ctype.h>
  35. #include <varargs.h>
  36.  
  37. #include "obstack.h"
  38.  
  39. #if defined (HAVE_STRING_H) || defined (STDC_HEADERS)
  40. #include <string.h>
  41. #ifndef index
  42. #define    index(s, c)    strchr ((s), (c))
  43. #endif
  44. #ifndef rindex
  45. #define    rindex(s, c)    strrchr ((s), (c))
  46. #endif
  47.  
  48. #ifdef NEED_MEMORY_H
  49. #include <memory.h>
  50. #endif /* NEED_MEMORY_H */
  51.  
  52. /* This is for obstack code -- should live in obstack.h.  */
  53. #define bcopy(s,d,n)    memcpy ((d), (s), (n))
  54. #else /* not HAVE_STRING_H and not STDC_HEADERS */
  55. #include <strings.h>
  56.  
  57. extern void bcopy ();
  58. #endif /* not HAVE_STRING_H and not STDC_HEADERS */
  59.  
  60. #ifdef STDC_HEADERS
  61. #include <stdlib.h>
  62. #else /* STDC_HEADERS */
  63. extern void *malloc ();
  64. extern void *realloc ();
  65. extern char *getenv ();
  66. #endif /* STDC_HEADERS */
  67.  
  68. extern char *mktemp ();
  69.  
  70.  
  71.  
  72. #define obstack_chunk_alloc    xmalloc
  73. #define obstack_chunk_free    xfree
  74.  
  75. /* If FALSE is defined, we presume TRUE is defined too.  In this case,
  76.    merely typedef boolean as being int.  Or else, define these all.  */
  77. #ifndef FALSE
  78. /* Do not use `enum boolean': this tag is used in SVR4 <sys/types.h>.  */
  79. typedef enum { FALSE = 0, TRUE = 1 } boolean;
  80. #else
  81. typedef int boolean;
  82. #endif
  83.  
  84. #include <errno.h>
  85. #ifndef errno
  86. extern int errno;
  87. #endif
  88.  
  89. extern int sys_nerr;
  90. extern char *sys_errlist[];
  91.  
  92. #define syserr() ((errno > 0 && errno < sys_nerr) ? sys_errlist[errno] : "Unknown error")
  93.  
  94.  
  95. /* Miscellaneous, that must come first.  */
  96. typedef void builtin_func ();
  97. typedef struct token_data token_data;
  98.  
  99.  
  100. /* File: m4.c  --- global definitions.  */
  101.  
  102. /* Option flags.  */
  103. extern int sync_output;            /* -s */
  104. extern int debug_level;            /* -d */
  105. extern int hash_table_size;        /* -H */
  106. extern int ndiversion;            /* -N */
  107. extern int no_gnu_extensions;        /* -g */
  108. extern int max_debug_argument_length;    /* -l */
  109. extern int suppress_warnings;        /* -Q */
  110.  
  111. /* Error handling.  */
  112. extern void warning ();        /* varargs */
  113. extern void error ();        /* varargs */
  114. extern volatile void fatal ();    /* varargs */
  115. extern volatile void internal_error ();    /* varargs */
  116.  
  117. /* Memory allocation.  */
  118. extern void *xmalloc Args ((unsigned int));
  119. extern void *xrealloc Args ((void *, unsigned int));
  120. extern void xfree Args ((void *));
  121. extern char *xstrdup Args ((const char *));
  122.  
  123.  
  124. /* File: debug.c  --- debugging and tracing function.  */
  125.  
  126. /* debug_level is a bitmask of these.  */
  127. enum debug_info
  128. {
  129.   DEBUG_TRACE_ARGS = 0x01,    /* a: show arglist in trace output */
  130.   DEBUG_TRACE_EXPANSION = 0x02,    /* e: show expansion in trace output */
  131.   DEBUG_TRACE_QUOTE = 0x04,    /* q: quote args and expansion in trace output */
  132.   DEBUG_TRACE_ALL = 0x08,    /* t: trace all macros -- overrides trace{on,off} */
  133.   DEBUG_TRACE_LINE = 0x10,    /* l: add line numbers to trace output */
  134.   DEBUG_TRACE_FILE  = 0x20,    /* f: add file name to trace output */
  135.   DEBUG_TRACE_PATH = 0x40,    /* p: trace path search of include files */
  136.   DEBUG_TRACE_CALL = 0x80,    /* c: show macro call before args collection */
  137.   DEBUG_TRACE_INPUT = 0x100,    /* i: trace changes of input files */
  138.   DEBUG_TRACE_CALLID = 0x200,    /* x: add call id to trace output */
  139.  
  140.   DEBUG_TRACE_VERBOSE = 0x3ff,    /* V: very verbose --  print everything */
  141.   DEBUG_TRACE_DEFAULT = 0x07    /* default flags -- equiv: aeq */
  142. };
  143.  
  144. extern void debug_init Args ((void));
  145. extern int debug_decode Args ((char *));
  146. extern boolean debug_set_output Args ((char *));
  147. extern void debug_print ();    /* varargs */
  148. extern void debug_message ();    /* varargs */
  149.  
  150. extern void trace_prepre Args ((char *, int));
  151. extern void trace_pre Args ((char *, int, int, token_data **));
  152. extern void trace_post Args ((char *, int, int, token_data **, char *));
  153.  
  154.  
  155. /* File: input.c  --- lexical definitions.  */
  156.  
  157. /* Various different token types.  */
  158. enum token_type
  159. {
  160.   TOKEN_EOF,            /* end of file */
  161.   TOKEN_STRING,            /* a quoted string */
  162.   TOKEN_WORD,            /* an identifier */
  163.   TOKEN_SIMPLE,            /* a single character */
  164.   TOKEN_MACDEF            /* a macros definition (see "defn") */
  165. };
  166.  
  167. /* The amount of data for a token, a macro argument, and a macro definition.
  168.    */
  169. enum token_data_type
  170. {
  171.   TOKEN_VOID,
  172.   TOKEN_TEXT,
  173.   TOKEN_FUNC
  174. };
  175.  
  176. struct token_data
  177. {
  178.   enum token_data_type type;
  179.   union
  180.     {
  181.       struct
  182.     {
  183.       char *text;
  184.     }
  185.       u_t;
  186.       struct
  187.     {
  188.       builtin_func *func;
  189.       boolean traced;
  190.     }
  191.       u_f;
  192.     }
  193.   u;
  194. };
  195.  
  196. #define TOKEN_DATA_TYPE(td)        ((td)->type)
  197. #define TOKEN_DATA_TEXT(td)        ((td)->u.u_t.text)
  198. #define TOKEN_DATA_FUNC(td)        ((td)->u.u_f.func)
  199. #define TOKEN_DATA_FUNC_TRACED(td)     ((td)->u.u_f.traced)
  200.  
  201. typedef enum token_type token_type;
  202. typedef enum token_data_type token_data_type;
  203.  
  204. extern void input_init Args ((void));
  205. extern int peek_input Args ((void));
  206. extern token_type next_token Args ((token_data *));
  207. extern void skip_line Args ((void));
  208.  
  209. /* push back input */
  210. extern void push_file Args ((FILE *, const char *));
  211. extern void push_macro Args ((builtin_func *, boolean));
  212.  
  213. extern struct obstack *push_string_init Args ((void));
  214. extern char *push_string_finish Args ((void));
  215.  
  216. extern void push_wrapup Args ((char *));
  217. extern boolean pop_wrapup Args ((void));
  218.  
  219. /* current input file, and line */
  220. extern char *current_file;
  221. extern int current_line;
  222.  
  223. /* left and right quote, begin and end comment */
  224. extern char *bcomm, *ecomm;
  225. extern char *lquote, *rquote;
  226. /* lenght of quote strings */
  227. extern int len_lquote, len_rquote;
  228.  
  229. #define DEF_LQUOTE "`"
  230. #define DEF_RQUOTE "\'"
  231. #define DEF_BCOMM "#"
  232. #define DEF_ECOMM "\n"
  233.  
  234. extern void set_quotes Args ((char *, char *));
  235. extern void set_comment Args ((char *, char *));
  236.  
  237.  
  238. /* File: output.c --- output functions.  */
  239. extern int output_current_line;
  240.  
  241. #define NDIVERSIONS    10    /* default, overridden by -Nnum */
  242.  
  243. extern void output_init Args ((void));
  244. extern void shipout_text Args ((struct obstack *, char *));
  245. extern void make_diversion Args ((int));
  246. extern void insert_diversion Args ((int));
  247. extern void insert_file Args ((FILE *));
  248.  
  249.  
  250. /* File symtab.c  --- symbol table definitions.  */
  251.  
  252. /* Operation modes for lookup_symbol ().  */
  253. enum symbol_lookup
  254. {
  255.   SYMBOL_LOOKUP,
  256.   SYMBOL_INSERT,
  257.   SYMBOL_DELETE,
  258.   SYMBOL_PUSHDEF,
  259.   SYMBOL_POPDEF
  260. };
  261.  
  262. /* Symbol table entry.  */
  263. struct symbol
  264. {
  265.   struct symbol *next;
  266.   boolean traced;
  267.   boolean shadowed;
  268.   boolean macro_args;
  269.  
  270.   char *name;
  271.   token_data data;
  272. };
  273.  
  274. #define SYMBOL_NEXT(s)        ((s)->next)
  275. #define SYMBOL_TRACED(s)    ((s)->traced)
  276. #define SYMBOL_SHADOWED(s)    ((s)->shadowed)
  277. #define SYMBOL_MACRO_ARGS(s)    ((s)->macro_args)
  278. #define SYMBOL_NAME(s)        ((s)->name)
  279. #define SYMBOL_TYPE(s)        (TOKEN_DATA_TYPE (&(s)->data))
  280. #define SYMBOL_TEXT(s)        (TOKEN_DATA_TEXT (&(s)->data))
  281. #define SYMBOL_FUNC(s)        (TOKEN_DATA_FUNC (&(s)->data))
  282.  
  283. typedef enum symbol_lookup symbol_lookup;
  284. typedef struct symbol symbol;
  285. typedef void hack_symbol ();
  286.  
  287. #define HASHMAX 509        /* default, overridden by -Hsize */
  288.  
  289. extern symbol **symtab;
  290.  
  291. extern void symtab_init Args ((void));
  292. extern symbol *lookup_symbol Args ((const char *, symbol_lookup));
  293.  
  294. extern void hack_all_symbols Args ((hack_symbol *, char *));
  295.  
  296.  
  297. /* File: macro.c  --- macro expansion.  */
  298.  
  299. extern void expand_input Args ((void));
  300. extern void call_macro Args ((symbol *, int, token_data **, struct obstack *));
  301.  
  302.  
  303. /* File: builtin.c  --- builtins.  */
  304.  
  305. struct builtin
  306. {
  307.   char *name;
  308.   boolean gnu_extension;
  309.   boolean groks_macro_args;
  310.   builtin_func *func;
  311. };
  312.  
  313. struct predefined
  314. {
  315.   const char *unix_name;
  316.   const char *gnu_name;
  317.   const char *func;
  318. };
  319.  
  320. typedef struct builtin builtin;
  321. typedef struct predefined predefined;
  322.  
  323. extern void builtin_init Args ((void));
  324. extern void define_user_macro Args ((const char *, const char *, symbol_lookup));
  325. extern void undivert_all Args ((void));
  326. extern void expand_user_macro Args ((struct obstack *, symbol *, int, token_data **));
  327.  
  328. extern const builtin *find_builtin_by_addr Args ((builtin_func *));
  329.  
  330.  
  331. /* File: path.c  --- path search for include files.  */
  332.  
  333. extern void include_init Args ((void));
  334. extern void include_env_init Args ((void));
  335. extern void add_include_directory Args ((char *));
  336. extern FILE *path_search Args ((const char *));
  337.  
  338.  
  339. /* File: eval.c  --- expression evaluation.  */
  340.  
  341. extern boolean evaluate Args ((char *, int *));
  342.  
  343.  
  344. /* File: format.c  --- printf like formatting.  */
  345.  
  346. extern void format Args ((struct obstack *, int, token_data **));
  347.  
  348.  
  349. /* Debug stuff.  */
  350.  
  351. #ifdef DEBUG
  352. #define DEBUG_INPUT
  353. #define DEBUG_MACRO
  354. #define DEBUG_SYM
  355. #define DEBUG_INCL
  356. #endif
  357.